<!DOCTYPE html>
<html>
<head>
    <meta charset='utf-8'>
    <meta http-equiv='X-UA-Compatible' content='IE=edge'>
    <title>Page Title</title>
    <meta name='viewport' content='width=device-width, initial-scale=1'>
    <link rel='stylesheet' type='text/css' media='screen' href='main.css'>
    <script src='main.js'></script>
</head>
<body>
    
</body>
<script>
    // 1. 将字符串数组用|连接
const names = ["刘备", "张飞", "关羽"];

let result2 = "";
for (let i = 0; i < names.length; i++) {
    result2 += names[i];
    if (i < names.length - 1) {
        result2 += "|";
    }
}
console.log("结果：", result2);     
</script>
<script>
    // 2. 反转数组元素顺序
const arr = ["a", "b", "c", "d"];

const reversed2 = [];
for (let i = arr.length - 1; i >= 0; i--) {
    reversed2.push(arr[i]);
}
console.log("结果：", reversed2);  
</script>
<script>
    // 3. 过滤掉超过2000的工资
const salaries = [1500, 1200, 2000, 2100, 1800];
const filteredSalaries = salaries.filter(salary => salary <= 2000);
console.log("过滤结果：", filteredSalaries); 
</script>
<script>
    // 4. 查找数组中每个'a'出现的位置
const letters = ["c", "a", "z", "a", "x", "a"];
const positions = [];
letters.forEach((letter, index) => {
    if (letter === "a") {
        positions.push(index);
    }
});
console.log("字母'a'的位置：", positions); 
</script>
<script>
    // 5. 去除数组中的重复元素
const arrWithDuplicates = [1, 2, 2, 3, 4, 4, 5];

const unique1 = [...new Set(arrWithDuplicates)];
console.log("结果：", unique1);

</script>
</html>